package com.lantosec.hmrp.modules.eval.controller;


import com.lantosec.hmrp.core.kit.PageVO;
import com.lantosec.hmrp.core.log.ControllerLog;
import com.lantosec.hmrp.core.log.LogType;
import org.springframework.web.bind.annotation.RequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.lantosec.hmrp.core.kit.Result;
import com.lantosec.hmrp.modules.eval.entity.EvalApplyDetail;
import com.lantosec.hmrp.modules.eval.service.IEvalApplyDetailService;
import com.lantosec.hmrp.modules.eval.vo.EvalApplyDetailVO;

import java.util.Arrays;
import java.util.List;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.RestController;
import com.lantosec.hmrp.core.mvc.BaseController;

/**
 *
 * 奖惩申报项目明细 控制器
 *
 * @author AutoCode
 * @since 2020-06-23
 */
@Api(value = "奖惩申报项目明细控制器", tags = "奖惩申报项目明细控制器")
@RestController
@RequestMapping("/eval/apply/detail")
@Log4j2
public class EvalApplyDetailController extends BaseController {
    @Autowired
    private IEvalApplyDetailService service;

    @GetMapping("getEvalApplyAll")
    @ApiOperation(value = "查询全部申报记录")
    public Result<PageVO<EvalApplyDetailVO>> getEvalApplyAll(@ApiParam(value = "分页对象", required = true) PageVO<EvalApplyDetailVO> page){
        service.getEvalApplyAll(page);
        return Result.ok(page);
    }

    @GetMapping("getDeptExamineAll")
    @ApiOperation(value = "查询全院人员申报记录")
    public Result<PageVO<EvalApplyDetailVO>> getDeptExamineAll(@ApiParam(value = "分页对象", required = true) PageVO<EvalApplyDetailVO> page){
        service.getDeptExamineAll(page);
        return Result.ok(page);
    }

    @GetMapping("getApplyExamineUser")
    @ApiOperation(value = "查询个人申报记录")
    public Result<PageVO<EvalApplyDetailVO>> getApplyExamineUser(@ApiParam(value = "分页对象", required = true) PageVO<EvalApplyDetailVO> page){
        service.getApplyExamineUser(page);
        return Result.ok(page);
    }

    @GetMapping("getApplyExamineDept")
    @ApiOperation(value = "查询科室人员申报记录")
    public Result<PageVO<EvalApplyDetailVO>> getApplyExamineDept(@ApiParam(value = "分页对象", required = true) PageVO<EvalApplyDetailVO> page){
        service.getApplyExamineDept(page);
        return Result.ok(page);
    }

    @GetMapping("getApplyExamineOurDept")
    @ApiOperation(value = "查询本科室申报记录")
    public Result<PageVO<EvalApplyDetailVO>> getApplyExamineOurDept(@ApiParam(value = "分页对象", required = true) PageVO<EvalApplyDetailVO> page){
        service.getApplyExamineOurDept(page);
        return Result.ok(page);
    }

    @GetMapping("getApplyExamineAllDept")
    @ApiOperation(value = "查询全院科室申报记录")
    public Result<PageVO<EvalApplyDetailVO>> getApplyExamineAllDept(@ApiParam(value = "分页对象", required = true) PageVO<EvalApplyDetailVO> page){
        service.getApplyExamineAllDept(page);
        return Result.ok(page);
    }

    @GetMapping("getDeptExamine")
    @ApiOperation(value = "项目审核（科室）列表")
    public Result<PageVO<EvalApplyDetailVO>> getDeptExamine(@ApiParam(value = "分页对象", required = true) PageVO<EvalApplyDetailVO> page){
        service.getDeptExamine(page);
        return Result.ok(page);
    }

    @GetMapping("getUserExamine")
    @ApiOperation(value = "项目审核（个人）列表")
    public Result<PageVO<EvalApplyDetailVO>> getUserExamine(@ApiParam(value = "分页对象", required = true) PageVO<EvalApplyDetailVO> page){
        service.getUserExamine(page);
        return Result.ok(page);
    }

    @PutMapping("updateDeptExamine")
    @ControllerLog(name = "科室项目审核", type = LogType.update)
    @ApiOperation(value = "科室项目审核")
    public Result<Void> updateDeptExamine(@ApiParam(value = "奖惩申报项目明细VO对象", required = true) @RequestBody EvalApplyDetailVO vo){
        service.updateDeptExamine(vo);
        return Result.ok();
    }

    @PutMapping("updateDeptExamineList")
    @ControllerLog(name = "科室项目批量审核", type = LogType.update)
    @ApiOperation(value = "科室项目批量审核")
    public Result<Void> updateDeptExamineList(@ApiParam(value = "奖惩申报项目明细VO对象", required = true) @RequestBody List<EvalApplyDetailVO> voList){
        service.updateDeptExamineList(voList);
        return Result.ok();
    }

    @PutMapping("updateUserExamine")
    @ControllerLog(name = "个人项目审核", type = LogType.update)
    @ApiOperation(value = "个人项目审核")
    public Result<Void> updateUserExamine(@ApiParam(value = "奖惩申报项目明细VO对象", required = true) @RequestBody EvalApplyDetailVO vo){
        service.updateUserExamine(vo);
        return Result.ok();
    }

    @PutMapping("updateUserExamineList")
    @ControllerLog(name = "个人项目批量审核", type = LogType.update)
    @ApiOperation(value = "个人项目批量审核")
    public Result<Void> updateUserExamineList(@ApiParam(value = "奖惩申报项目明细VO对象", required = true) @RequestBody List<EvalApplyDetailVO> voList){
        service.updateUserExamineList(voList);
        return Result.ok();
    }

    @PostMapping("create")
    @ControllerLog(name = "奖惩申报项目明细", type = LogType.add)
    @ApiOperation(value = "新增数据")
    public Result<Integer> create(@ApiParam(value = "奖惩申报项目明细VO对象", required = true) @RequestBody @Validated EvalApplyDetailVO vo, BindingResult bindingResult){
        validationHandler(bindingResult);
        EvalApplyDetail entity = vo.convertToEntity();
        service.save(entity);
        return Result.ok(entity.getEvalApplyDetailId());
    }

    @DeleteMapping(value = "delete/{ids}")
    @ControllerLog(name = "逻辑删除奖惩申报项目", type = LogType.delete)
    @ApiOperation("逻辑删除")
    public Result<Void> delete(@ApiParam(value = "ID列表,用逗号分隔", required = true) @PathVariable(name="ids") String ids){
        if(StringUtils.isNotEmpty(ids)){
            service.removeByIds(Arrays.asList(ids.split(",")));
        }
        return Result.ok();
    }
}
